package com.ruisi.operateClasses;

import java.util.HashMap;
import java.util.List;

import com.ruisi.weatherreport.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class listViewAdapter extends BaseAdapter{
       private LayoutInflater mInflater;
       List<HashMap<String,Object>> list;
              
       public listViewAdapter(Context context,List<HashMap<String,Object>> list){
    	   this.list=list;
    	   this.mInflater=LayoutInflater.from(context);
       }
       
       public int getCount(){
    	   return list.size();
       }
       
       public Object getItem(int position){
    	   return list.get(position);
       }
       
       public long getItemId(int position){
    	   return position;
       }
       
       public View getView(int position,View convertView,ViewGroup parent){
    	   ViewHolder mholder;
    	   if(convertView==null){
    		   mholder=new ViewHolder();
    		   convertView=mInflater.inflate(R.layout.sqlitedatabaseitem, null);
    		   mholder.tv_id=(TextView)convertView.findViewById(R.id.tv_personID);
    		   mholder.tv_name=(TextView)convertView.findViewById(R.id.tv_personName);
    		   convertView.setTag(mholder);
    	   }else{
    		   mholder=(ViewHolder)convertView.getTag();
    	   }
    	   mholder.tv_id.setText(""+list.get(position).get("id"));   	   
    	  // Log.v("list", "id="+mholder.tv_id);
    	   mholder.tv_name.setText((String)list.get(position).get("name"));
    	   
    	   return convertView;
       }
       
       private final class ViewHolder{
    		TextView tv_id;
    		TextView tv_name;
    	}
}

